<?php

class backendInit{

	function __construct() {
		add_action('admin_menu', array(&$this, 'init_menu'));
		add_action('admin_menu', array(&$this, 'mytheme_add_init'));
		add_action('admin_init', array(&$this, 'mytheme_add_init'));
	}
	
	public function init_menu(){
		add_menu_page('Настройки темки', 'Настройки темки', 'manage_options', 'theme_options', array(&$this, 'global_theme_options'));
	}
	
	public function global_theme_options(){
		if($_POST['oscimp_hidden'] == 'Y') {
			$theme_slogan = $_POST['theme_slogan']; update_option('theme_slogan', $theme_slogan);
			$theme_color = $_POST['theme_color']; update_option('theme_color', $theme_color);
			$theme_display_copy = $_POST['theme_display_copy']; update_option('theme_display_copy', $theme_display_copy);
			$theme_copyright = $_POST['theme_copyright']; update_option('theme_copyright', $theme_copyright);
			$theme_phone_1 = $_POST['theme_phone_1']; update_option('theme_phone_1', $theme_phone_1);
			$theme_phone_1_display = $_POST['theme_phone_1_display']; update_option('theme_phone_1_display', $theme_phone_1_display);
			$theme_phone_2 = $_POST['theme_phone_2']; update_option('theme_phone_2', $theme_phone_2);
			$theme_phone_2_display = $_POST['theme_phone_2_display']; update_option('theme_phone_2_display', $theme_phone_2_display);
			$theme_phone_3 = $_POST['theme_phone_3']; update_option('theme_phone_3', $theme_phone_3);
			$theme_phone_3_display = $_POST['theme_phone_3_display']; update_option('theme_phone_3_display', $theme_phone_3_display);
			$theme_featured_post = $_POST['theme_featured_post']; update_option('theme_featured_post', $theme_featured_post);
			
			?>
			<div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div>
			<?php
		} else {
			$theme_slogan = get_option('theme_slogan');
			$theme_color = get_option('theme_color');
			$theme_display_copy = get_option('theme_display_copy');
			$theme_copyright = get_option('theme_copyright');
			$theme_phone_1 = get_option('theme_phone_1');
			$theme_phone_1_display = get_option('theme_phone_1_display');
			$theme_phone_2 = get_option('theme_phone_2');
			$theme_phone_2_display = get_option('theme_phone_2_display');
			$theme_phone_3 = get_option('theme_phone_3');
			$theme_phone_3_display = get_option('theme_phone_3_display');
			$theme_featured_post = get_option('theme_featured_post');
			
		}
		?>
		<div class="wrap">
			<div class="icon32" id="icon-tools"><br></div>
			<h2>Easy Cpanel standart</h2>
			<form name="oscimp_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
				<input type="hidden" name="oscimp_hidden" value="Y">				
					<span class="field_name">Слоган сайта</span>
					<span class="field_description">Введите девиз Вашей фирмы</span>
						<input type="text" name="theme_slogan" value="<?php echo $theme_slogan; ?>" maxlength="255"/>
					<span class="field_name">Цветовая схема</span>
					<span class="field_description">Выберите цветовую схему Вашей темки</span>
						<select name="theme_color">
							<option value="red" <?php if(get_option('theme_color') == "red") echo 'selected="selected"';?>>Красный</option>
							<option value="black" <?php if(get_option('theme_color') == "black") echo 'selected="selected"';?>>Черный</option>
							<option value="green" <?php if(get_option('theme_color') == "green") echo 'selected="selected"';?>>Зелёный</option>
							<option value="blue" <?php if(get_option('theme_color') == "blue") echo 'selected="selected"';?>>Синий</option>
						</select>
					<span class="field_name">Отображать копирайт?</span>
					<span class="field_description">Выберите "Да" или "Нет" для того чтобы отображать или не отображать копирайт</span>
						<input type="radio" name="theme_display_copy" value="1" id="theme_display_copy_1" <?php if(get_option('theme_display_copy') == "1") echo 'checked="checked"';?>/> <label for="theme_display_copy_1">Да</label><br/>
						<input type="radio" name="theme_display_copy" value="0" id="theme_display_copy_0" <?php if(get_option('theme_display_copy') == "0") echo 'checked="checked"';?>/> <label for="theme_display_copy_0">Нет</label>
					<span class="field_name">Копирайт</span>
					<span class="field_description">Введите текст копирайта</span>
						<textarea name="theme_copyright"><?php echo $theme_copyright; ?></textarea>
					<span class="field_name">Телефоны</span>
					<span class="field_description">Введите номера телефонов, и для подтверждения отметьте телефон галочкой</span>
						<input type="text" name="theme_phone_1" value="<?php echo $theme_phone_1; ?>" maxlength="255"/>
						<input type="checkbox" name="theme_phone_1_display" <?php if(get_option('theme_phone_1_display') == "on") echo 'checked="checked"';?>/><br/>
						<input type="text" name="theme_phone_2" value="<?php echo $theme_phone_2; ?>" maxlength="255"/>
						<input type="checkbox" name="theme_phone_2_display" <?php if(get_option('theme_phone_2_display') == "on") echo 'checked="checked"';?>/><br/>
						<input type="text" name="theme_phone_3" value="<?php echo $theme_phone_3; ?>" maxlength="255"/>
						<input type="checkbox" name="theme_phone_3_display" <?php if(get_option('theme_phone_3_display') == "on") echo 'checked="checked"';?>/>
					<span class="field_name">Запись на главной</span>
					<span class="field_description">Выберите статью которая должна отображаться на главной странице</span>
						<select name="theme_featured_post">
							<?php 
							$posts_array = get_posts();
							foreach ($posts_array as $post):
							?>
							<option value="<?php echo $post->ID; ?>" <?php if(get_option('theme_featured_post') == $post->ID) echo 'selected="selected"';?>><?php echo $post->post_title; ?></option>
							<?php endforeach; ?>
						</select>
					<div class="media-upload">
						<span class="field_name">Загрузить файл</span>
						<span class="field_description">Виберите файл для загрузки</span>
							<input id="upload_image_button" type="button" value="Загрузить файл">
						
					</div>
					<input type="submit" name="Submit" class="button-primary" value="<?php _e('Update Options') ?>" />				
			</form>
		</div>	
		<?php function media_uploader_box() { global $post;} ?>
		<script>
			( function( $ ) {
			   $(document).ready(
				   function()
				   {
						 $('#upload_image_button').click(
							 function()
							 {
								 tb_show('', 'media-upload.php?post_id=<?php  echo $post->ID; ?>&type=image&amp;TB_iframe=true');
								 return false;
							 }
						 );
				   }
			   );
			} ) ( jQuery );
		</script>

		
	<?php
	}
	public function mytheme_add_init(){
		if (isset($_GET['page']) && $_GET['page'] == 'theme_options') {
			add_action('admin_print_scripts', array(&$this, 'my_admin_scripts'));
			add_action('admin_print_styles', array(&$this, 'my_admin_styles'));
		}
	}
	public function my_admin_scripts() {
		wp_enqueue_script(false, get_bloginfo('template_directory')."/features/admin.js", false, false);
	}

	public function my_admin_styles() {
		wp_enqueue_style(false, get_bloginfo('template_directory')."/features/admin.css", false, "1.0", "all");
	}
}
$init = new backendInit();